{% extends 'manage/base_manage.html' %}
{% load static %}
{% block title %}Bug管理列表{% endblock %}

{% block css %}
    <link rel="stylesheet" href="{% static 'css/bug/bug_manage.css' %}">
{% endblock %}

{% block content %}
    <div class="content">
        <div id="product_content">
            <h3 id="add_product_name">Bug列表</h3>
            <a id="add_product" href="{% url 'atp:bug_add' %}">＋添加Bug</a>
            <div id="search_p">
                <form method="get" action="{% url 'atp:bug_search' %}">
                    {% csrf_token %}
                    <div class="form-group">
                        <br><br>
                        <input name="bug_name" type="search" class="form-control"
                               placeholder="输入Bug名称">
                        <button type="submit" id="search_b" class="btn btn-default">搜索</button>
                    </div>
                </form>
            </div>
            <form id="" method="post" action="">
                {% csrf_token %}
                <table class="table-striped" id="table_list">
                    <thead>
                    <tr id="tr_title">
                        <th id="table_title_length">ID</th>
                        <th id="table_title_length3">产品名称</th>
                        <th id="table_title_length3">Bug名称</th>
                        <th id="table_title_length2">Bug详情</th>
                        <th id="table_title_length">严重程度</th>
                        <th id="table_title_length">解决状态</th>
                        <th id="table_title_length">创建人</th>
                        <th id="table_title_length">分配给</th>
                        <th id="table_title_length3">创建时间</th>
                        <th id="table_title_length">编辑</th>
                        <th id="table_title_length">删除</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for bug in bugs %}
                        <tr id="tr_d">
                            <td>{{ bug.id }}</td>
                            <td>{{ bug.bug_pro.product_name }}</td>
                            <td>{{ bug.bug_name }}</td>
                            <td>{{ bug.bug_detail }}</td>
                            <td>{% if bug.bug_level == "low" %}
                                <a style="color:green;text-decoration: none;">{{ bug.get_bug_level_display }}</a>
                            {% elif bug.bug_level == "mid" %}
                                <a style="color:gold;text-decoration: none;">{{ bug.get_bug_level_display }}</a>
                            {% elif bug.bug_level == "high" %}
                                <a style="color:red;text-decoration: none;">{{ bug.get_bug_level_display }}</a>
                            {% endif %}
                            </td>
                            <td>{% if bug.bug_status == "0" %}
                                <a style="color:red;text-decoration: none;">激活</a>
                            {% elif bug.bug_status == "1" %}
                                <a style="color:green;text-decoration: none;">已解决</a>
                            {% elif bug.bug_status == "2" %}
                                <a style="color: black;text-decoration: none;">已关闭</a>
                            {% endif %}
                            </td>
                            <td>{{ bug.bug_creat_er }}</td>
                            <td>{{ bug.bug_assign }}</td>
                            <td>{{ bug.create_time }}</td>
                            <td><a style="color:cadetblue " href="{% url 'atp:bug_update' bug.id %}">编辑</a></td>
                            <td><a style="color: #cc0000" href="javascript:"
                                   onclick="confirm_delete({{ bug.id }})">删除</a>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </form>
            <!--分页-->
            <div id="pager">
                <nav aria-label="Page navigation">
                    <ul class="pagination">
                        {% if bugs.has_previous %}
                            <li>
                                <a href="?page={{ bugs.previous_page_number }}&bug_name={{ search_name }}"
                                   aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                        {% else %}
                            <li class="disabled">
                                <a href="#" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        {% endif %}

                        {% for page_index in bugs.paginator.page_range %}
                            {% ifequal page_index  bugs.number %}
                                <li class="active">
                                    <a style="background: cadetblue"
                                       href="?bug_name={{ search_name }}&page={{ page_index }}">{{ page_index }}</a>
                                </li>
                            {% else %}
                                <li>
                                    <a href="?bug_name={{ search_name }}&page={{ page_index }}">{{ page_index }}</a>
                                </li>
                            {% endifequal %}
                        {% endfor %}

                        {% if bugs.has_next %}
                            <li>
                                <a href="?page={{ bugs.next_page_number }}&bug_name={{ search_name }}"
                                   aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        {% else %}
                            <li class="disabled">
                                <a href="#" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        {% endif %}
                    </ul>
                </nav>
            </div>
        </div>
    </div>
{% endblock %}

{% block js %}
    <script>

        function confirm_delete(bug_id) {
            layer.open({
                title: "是否确认删除?",
                btn: ['确定', '取消'],
                yes: function () {
                    $.ajax({
                        url: "{% url 'atp:bug_delete'  %}",
                        type: "GET",
                        dataType: "JSON",
                        data: {"bug_id": bug_id},
                        success: function (res) {
                            if (res.code === 200) {
                                layer.msg('删除成功');
                                setTimeout(function () {
                                    parent.location.reload();
                                }, 1000);
                            } else {
                                layer.msg('删除失败');
                                setTimeout(function () {
                                    parent.location.reload();
                                }, 1000);
                            }
                        }
                    })
                }
            })
        }
    </script>
{% endblock %}